<?php
namespace app\admin\controller;
use think\Controller;
use app\admin\model\Checks;
use think\Request;
use think\Db;

/**
 * Created by PhpStorm.
 * User: 空房间
 * Date: 2018/2/17
 * Time: 13:59
 */
class Check extends Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->db=new checks;
    }
    /**
     * 检查方案列表
     */
    public function check_list()
    {
        $info_list  = $this->db->checks_list();
        $this->assign('info_list',$info_list);
        return view();
    }
    /**
     * 检查方案添加
     */
    public function check_add()
    {
        if(Request::instance()->isPost()){
            $data = input('post.');
            $info = array(
                'title'              => $data['title'],
                'hospital_id'       =>  23,   //待修改
                'operator_id'       =>  22,   //待修改
                'price'              =>  $data['price']
            );
            $result = $this->db->save_info($info);
            $result ? $this->success('成功') : $this->error('失败');
        }
        return view();
    }
    /**
     * 检查方案修改
     */
    public function check_edit()
    {
        if(Request::instance()->isPost()){
            $data = input('post.');
            if(!isset($data['id'])||!$data['id']){
                $this->error('参数不全操作失败');die;
            }
            $info = array(
                'title'              => $data['title'],
                'hospital_id'       =>  23,   //待修改
                'operator_id'       =>  22,   //待修改
                'price'              =>  $data['price']
            );
            $result = $this->db->update_info($data['id'],$info);
            $result ? $this->success('成功') : $this->error('失败');
        }
        $id = input('get.id');
        $info = $this->db->getInfoById(array('id'=>$id));
        $this->assign('info',$info);
        return view();
    }
    /**
     * 检查方案删除
     */
    public function check_del()
    {
        $id=input('post.id',0,'intval');
        if(!$id){
           $result = array(
               'status' =>0,
               'message'=>'参数错误，无法删除'
           );
        }else{
            $re=$this->db->del_info($id);
            if(!$re){
                $result = array(
                    'status' =>0,
                    'message'=>'删除失败'
                );
            }else{
                $result = array(
                    'status' =>1,
                    'message'=>'删除成功'
                );
            }
        }
        echo json_encode($result);
    }
}